//
//  WPWithDrawsureVC.m
//  wobingwoyi
//
//  Created by WGP on 16/8/5.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPWithDrawsureVC.h"
#import "WPMineLoginVC.h"

@interface WPWithDrawsureVC ()

@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (weak, nonatomic) IBOutlet UILabel *coinCount;

@end

@implementation WPWithDrawsureVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.infoLabel.text = self.infoStr;
    self.coinCount.text = self.coinCountStr;
}

- (IBAction)cancel:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)sure:(id)sender
{
    
    NSString *url = @"user/withdraw.do";
    
    [[WPNetWorkManager sharedNetWorkManager] POST:url parameters:self.dict progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        if ([responseObject[@"result"] isEqualToString:@"success"])
        {
            [self showSuccessInfoWithStatus:@"信息提交成功,请耐心等待"];
            [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
        }
        else
        {
            
            //            考虑到账号过期的情况
            if ([responseObject[@"detail"] isEqualToString:@"illegalLogin"])
            {
                //                账号过期
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"账号过期,请重新登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alertView show];
            }
            else
            {
                [self showErrorInfoWithStatus:@"提现失败"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showErrorInfoWithStatus:@"网络错误"];
    }];
}

//重新登陆的代理方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
        if (buttonIndex == 0)
        {
            WPMineLoginVC *vc = [WPMineLoginVC new];
            [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
        }
}

@end
